import 'package:flutter/material.dart';
import 'package:myturngame/bean/bagobject/consume_object.dart';
import 'package:myturngame/bean/bagobject/equipment.dart';
import 'package:myturngame/widget/text_decoration.dart';

import '../../Theme.dart';
import '../../bean/bagobject/bag_object.dart';

///物品信息
WidgetBuilder objectInfoDialogBuilder(
    BagObject bagObject, Function operationCallback) {
  return (BuildContext context) {
    var childrens = [
      //名称
      Text(bagObject.name, style: textStyle2, textAlign: TextAlign.center),
      //普通属性
      Column(
        children: bagObject.objectFunctions
            .map((e) => Text.rich(TextSpan(children: e.description()),
                textAlign: TextAlign.center))
            .toList(),
      ),
    ];
    //套装属性
    if (bagObject is Equipment) {
      _showSuitFunction(childrens, bagObject);
    }
    childrens.addAll([
      //描述
      Text(bagObject.description,
          style: textStyleObjectDescription, textAlign: TextAlign.center),
      //操作
      const Divider(height: 10),
      operationLayout(bagObject, (operation) {
        operationCallback(operation);
        Navigator.pop(context);
      })
    ]);

    return Dialog(
      child: Padding(
        padding: const EdgeInsets.all(5),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: childrens,
        ),
      ),
    );
  };
}

///展示套装属性
void _showSuitFunction(List<Widget> children, Equipment bagObject) {
  var suit = bagObject.suit;
  if (suit != null) {
    children.add(Text(
      "${suit.name}(${suit.invokeCount})",
      style: suit.isInvoke
          ? textStyleFunctionSuit
          : textStyleFunctionSuitNotInvoke,
    ));
    children.add(Column(
      mainAxisSize: MainAxisSize.min,
      children: suit.suitFunctions
          .map((e) => Text.rich(TextSpan(children: e.description())))
          .toList(),
    ));
  }
}

///操作
Widget operationLayout(BagObject bagObject, Function operationCallback) {
  List<String> operationList = [];
  if (bagObject is Equipment) {
    if (bagObject.isEquip) {
      operationList.add("卸下");
    } else {
      operationList.add("装备");
    }
  } else if (bagObject is Consume) {
    operationList = ["使用"];
  }
  operationList.add("丢弃");
  return Row(
    mainAxisSize: MainAxisSize.min,
    children: operationList
        .map((e) => Padding(
              padding: const EdgeInsets.only(left: 5, right: 5),
              child: GestureDetector(
                onTap: () {
                  operationCallback(e);
                },
                child: BorderContainer(Text(e)),
              ),
            ))
        .toList(),
  );
}
